package com.example.hospital.api.service.impl;

import cn.hutool.core.map.MapUtil;
import com.example.hospital.api.db.dao.MedicalDeptDao;
import com.example.hospital.api.service.MedicalDeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class MedicalDeptServiceImpl implements MedicalDeptService {

    @Resource
    private MedicalDeptDao medicalDeptDao;
    @Override
    public List<HashMap> selectAll() {
        return medicalDeptDao.selectAll();
    }

    @Override
    public Map selectDeptAndSub() {
        List<HashMap> list = medicalDeptDao.selectDeptAndSub();
        LinkedHashMap<String,List> map = new LinkedHashMap<>();
        for (HashMap item : list) {
            Integer deptId = MapUtil.getInt(item, "deptId");
            Integer subId = MapUtil.getInt(item, "subId");
            String deptName = MapUtil.getStr(item, "deptName");
            String subName = MapUtil.getStr(item, "subName");
            HashMap<Object, Object> subMap = new HashMap<>();
            subMap.put("subId", subId);
            subMap.put("subName", subName);
            map.computeIfAbsent(deptName, e -> new ArrayList<>()).add(subMap);
        }
        return map;
    }


}
